import { hasAuth } from '@/plugins/permission';
// import { Directive, DirectiveBinding } from "vue";

/**
 * 按钮权限
 */
export const hasPerm = {
  mounted(el, binding) {
    // DOM绑定需要的按钮权限标识
    const requiredPerms = binding.value;
    if (requiredPerms) {
      if (!hasAuth(requiredPerms)) {
        if (el.parentNode) {
          el.parentNode.removeChild(el);
        }
      }
    } else {
      throw new Error(
        "need perms! Like v-has-perm=\"['sys:user:add','sys:user:edit']\"",
      );
    }
  },
};
